package cn.hf.mychat.teach.utils;

import org.apache.commons.lang3.StringUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 日期计算
 */
public class DateCalculate {

    private static final String TUESDAY = "星期二";
    private static final Integer WEEK_NUMBER = 7;

    public static void main(String[] args) {

    }

    /**
     * 原始天数，要加的天数，返回格式
     *
     * @param orgiginalDate
     * @param num
     * @param format
     * @return
     */
    public static String dayAdd(String orgiginalDate, int num, String format) {

        try {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            Date date = null;
            if (StringUtils.isNotBlank(orgiginalDate)) {
                date = dateFormat.parse(orgiginalDate);
            } else {
                date = new Date();
            }
            System.out.println("date = " + date);
            String time = "";
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            calendar.add(Calendar.DATE, num);
            String year = Integer.toString(calendar.get(Calendar.YEAR));
            String month = Integer.toString(calendar.get(Calendar.MARCH) + 1);
            String day = Integer.toString(calendar.get(Calendar.DATE));
            String newDate = year + "-" + month + "-" + day;
            Date dateTime = dateFormat.parse(newDate);
            if (StringUtils.isNotBlank(format)) {
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
                time = simpleDateFormat.format(dateTime);
            } else {
                time = dateFormat.format(dateTime);
            }
            return time;

        } catch (ParseException e) {
            e.printStackTrace();
        }
        return "";
    }
    //TODO

}
